package org.example.game.history;

import java.util.Arrays;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/07/06 23:06
 */
public class Solution100182 {

    public static void main(String[] args) {
        System.out.println(new Solution100182().maximumPoints(new int[]{2}, 10));
    }

    public long maximumPoints(int[] enemyEnergies, int currentEnergy) {

        //找出一个最小的， 其他的全部加起来 %最小的值
        int min = Integer.MAX_VALUE;
        long sum = 0;

        for (int enemyEnergy : enemyEnergies) {
            min = Math.min(enemyEnergy, min);
            sum+=enemyEnergy;
        }

        if(currentEnergy < min){
            return 0;
        }

        return (currentEnergy + sum - min)/min;

    }

    //敌人被标记完，或者 能力不够得分了
    public long maximumPoints2(int[] enemyEnergies, int currentEnergy) {

        int num = enemyEnergies.length;
        Arrays.sort(enemyEnergies);
        //得分
        int start = 0;
        //标记
        int end = num-1;
        int point = 0;
        if(currentEnergy < enemyEnergies[start]){
            return 0;
        }
        while (currentEnergy >= enemyEnergies[start] || num >0){
            if(currentEnergy >= enemyEnergies[start]){
                currentEnergy-=enemyEnergies[start];
                point++;
            }else if(point >= 1){
                currentEnergy+=enemyEnergies[end];
                end--;
                num--;
                if(end < 0){
                    break;
                }
            }
        }
        return point;
    }

}
